<template>
  <!--测评2-->
  <div>
      <div class="titleWrap">
        <p class="titleName" >我的能力</p>
        <span class="pull-right font14"><span @click.stop.prevent="backAblity" style="cursor: pointer">我的能力</span> > 能力天梯</span>
      </div>
      <ul class="ceping_lists clearfix">
        <li v-for="ability in abilityList" @click.stop="abilityCeping(ability.abilityitemId)">
          <div class="pull-left" >
            <p  v-if="ability.abilityitemCode === 'synthesis'">{{ability.abilityitem}}测评</p>
            <p  v-else>{{ability.abilityitem}}能力</p>
            <p>去测评 <Icon type="ios-arrow-forward" size="20"/></p>
          </div>
          <div  class="pull-right txt-center">
            <img :src="ability.duanIcon" alt="" width="70"/><br>{{ability.duanName}}
          </div>
        </li>
      </ul>
    <Spin fix v-show="isSpinShow" >
      <div class="loader">
        <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
        <div class="font14">加载中...</div>
      </div>
    </Spin>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }

  .titleWrap {
    height: 40px;
    font-size: 18px;
    padding-bottom: 20px;
    text-align: justify-all;
    border-bottom: 1px solid #E1E1E1;
    margin-bottom: 20px;
    color: #957960;
    .titleName {
      float: left;
      line-height: 24px;
      border-bottom: 3px solid #957960;
      padding-bottom: 13px;
      font-size: 14px;
    }
    .pull-right{
      /*font-size: 16px;*/
      color: #333;
    }
  }
  .title{
    font-size: 31px;
    color: #000;
    text-align: center;
  }
  .ceping_lists{
    margin-top: 30px;
    li{
      border: 1px solid #eee;
      border-top: 8px solid #957960;
      border-radius: 5px;
      padding: 20px 17px;
      float: left;
      margin-right: 25px;
      margin-bottom: 30px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      height: 140px;
      width: 236px;
      cursor: pointer;
      .pull-left{
        width: 120px;
        padding-top: 15px;
        p:first-child{
          font-size: 18px;
          color: #000;
          margin-bottom: 5px;
        }
        p:last-child{
          font-size: 14px ;
          color: #999;
          i{
            margin-left: 5px;
            margin-bottom: 2px;
          }
        }
      }
    }
    li:nth-child(3n){
      margin-right: 0;
    }
  }

</style>
<script type="text/ecmascript-6">
  import chart from '../template/chart'
  import {radarPage2,getSubject,centreInfoWeb,abilityPage} from '../../http'
  import {getStore} from '../../storage'
  import imgPathFilter from '../../myFilters'
  export default {
    name: 'ceping2',
    props: {},
    data() {
      return {
        isSpinShow:false,
        abilityList:'',   //能力级别
        leidaValue:[]     //雷达图数据
      };
    },
    methods: {
      //返回上级我的能力
      backAblity(){
        this.$router.push({
          name:'ablity'
        })
      },
      //测评
      abilityCeping(abilityitemId){
        if(this.isSpinShow === false) {
          this.isSpinShow = true;
          //用户是否登录
          centreInfoWeb().then(res => {
            if (res.code === 200) {
              /*//获取题目
              getSubject({abilityitemId: abilityitemId}).then(res => {
                //题库有相应题
                if (res.data.list.length > 0) {
                  abilityPage().then(res => {
                    if (res.code === 200) {
                      if (res.data.isBuy === 1) {
                        this.isSpinShow = false;
                        this.$router.push({
                          name: 'question',
                          query: {
                            abilityitemId: abilityitemId
                          }
                        })
                      } else {
                        this.isSpinShow = false;
                        this.$Notice.warning({
                          title: "人才测评提醒",
                          desc: "请先购买人才能力测评",
                          duration: 3,
                        });
                        this.$router.push({
                          name: 'ablity'
                        })
                      }
                    }else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "人才测评提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch()
                } else {        //题库暂无题目
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: "人才测评提醒",
                    desc: "题库无相应题目，请进行其他测试",
                    duration: 3,
                  });
                }
              }).catch();*/
              this.$router.push({name: 'ceping'});
            } else {
              this.isSpinShow = false;
              this.$router.push({name: 'ablity'});
            }
          })
        }
      },
      //能力数据整理
      getAbilities(arr){
        var newarr = new Array();
        var serarr = ["serve","finance","maintain","develop","marketing","manage"];
        for(let i = 0;i < serarr.length; i++){
          for(let j = 0;j < arr.length; j++){
            if(serarr[i] === arr[j].abilityitemCode){
              newarr.push(arr[j]);
              break;
            }
          }
        }
        return newarr;
      }
    },
    created() {
      if(this.isSpinShow === false) {
        this.isSpinShow = true;
        //用户是否登录
        centreInfoWeb().then(res => {
          if (res.code === 200) {
            //是否购买人才测评
            abilityPage().then(res => {
              if (res.code === 200) {
                if (res.data.isBuy === 1) {
                  //雷达图数据
                  radarPage2().then(res => {
                    this.isSpinShow = false;
                    this.abilityList = this.getAbilities(res.data.abilityList);
                  }).catch()
                } else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: "人才测评提醒",
                    desc: "请先购买人才能力测评",
                    duration: 3,
                  });
                  this.$router.push({
                    name: 'ablity'
                  })
                }
              }else {
                this.isSpinShow = false;
                this.$Notice.warning({
                  title: "人才测评提醒",
                  desc: res.info,
                  duration: 3,
                });
              }
            }).catch()
          } else {
            this.isSpinShow = false;
            this.$router.push({name: 'ablity'});
          }
        }).catch()
      }
    },
    components: {
      chart
    }
  }
</script>
